﻿namespace YdmCodeArtCoreApplication.Tests.TestDatas
{
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using FFF.Test.Application.Tests.TestDatas.DataInit;
    using FFF.Test.DataAccess.Framework;
    using FFF.Test.Entity.Demo;
    using Ydm.Extensions;

    public class TestDataBuilder
    {
        private readonly MyDbContext _context;

        public TestDataBuilder(MyDbContext context)
        {
            this._context = context;
        }

        public void Build()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            List<Type> initTypes = assembly.GetAllChildType(typeof(BaseInit));

            foreach (var type in initTypes)
            {
                var initType = Activator.CreateInstance(type) as BaseInit;
                initType.Excute(this._context);
            }
        }
    }
}